<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--<link href="../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">-->
		<link rel="stylesheet" type="text/css" href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />-->
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/gift_sell.css" />
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../../../css/store_member/style.css" />
		<style type="text/css">
			.gift_sell_wap ul li {
				height: 4.3rem;
			}
			
			body {
				overflow: auto;
			}
			
			button.f28_s:focus {
				outline: none;
			}
			
			.input-group-addon {
				width: 0.694444rem;
			}
			
			.red_border {
				border-bottom: 1px solid red;
			}
			
			.nav {
				background-color: #FFFFFF;
				margin-bottom: 0.3rem;
			}
		</style>
	</head>

	<body>
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="javascript:history.go(-1)"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">售卖礼品</p>
				</div>
				<div class="nav" style="overflow: hidden;margin-top:1.3rem;">
					<div style="float: left;padding:0.2rem 0 0.2rem 0;  text-align: center; width: 25%;">

						<span id="type111" class="f28_s active_red red_border" style=" padding-bottom:0.2rem;" onclick="all_product()">全部</span>

					</div>
					<div style="float: left; padding:0.2rem 0 0.2rem 0; text-align: center; width: 25%;">

						<span id="type222" class="f28_s " style="padding-bottom:0.2rem;" onclick="wei()">寄卖中</span>

					</div>

					<div style="float: left; padding:0.2rem 0 0.2rem 0;text-align: center; width: 25%;">

						<span id="type333" class="f28_s " style="padding-bottom:0.2rem;" onclick="yi()">完成寄卖</span>

					</div>
					<div style="float: left; padding:0.2rem 0 0.2rem 0;text-align: center; width: 25%;">

						<span id="type444" class="f28_s " style="padding-bottom:0.2rem;" onclick="yiShop()">已购买</span>

					</div>
				</div>
				<div id="content">
					<div class="gift_sell_wap">
						<ul id="gift_main" style="margin-top:-5px; height: 2.77777rem;">
							
						</ul>
					</div>
				</div>
			</div>
		</div>

	</body>
	<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		//	console.log(memberId)
		//登陆判断
		var tokenReztApp = $.cookie("tokenReztApp");
		if(!tokenReztApp) {
			window.location.href = "../../login/login/login.html";
		}
		$(function() {
			currentyf();
			all_product();
			canshu();
		});

		//用户信息
		var user, role, goodsId;
		//获取当前会员信息
		function currentyf() {
			$.ajax({
				cache: false,
				type: "GET",
				url: "http://47.104.13.109/member-service/auth/current?token=" + tokenReztApp,
				dataType: "JSON",
				async: false,
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$.removeCookie('tokenReztApp', {
						expires: 7,
						path: '/'
					});
					$.removeCookie("tokenRh", {
						expires: 7,
						path: '/'
					});
					$.removeCookie('memberId', {
						expires: 7,
						path: '/'
					});
					$.removeCookie('roleId', {
						expires: 7,
						path: '/'
					});
					window.location.href = "../../login/login/login.html";
				},
				success: function(data) {
					user = data.loginName;
					role = data.roleList[0].id; //角色
					goodsId = data.id;
					

				}
			});
		}
		
		var proportion;
		function canshu(){
			$.ajax({
				cache: false,
				type: "GET",
				url: "http://47.104.13.109/order-service/selectall",
				data: {
						"id": "2",
						"pageNum": "1",
						"pageSize": "100"
					 },
				dataType: "JSON",
				async: false,
				error: function(XMLHttpRequest, textStatus, errorThrown) {
				},
				success: function(data) {
					console.log(data.list[0].parameter);
					proportion = data.list[0].parameter;
				}
			});
		}


		var memberId = "";
		var pageNum = 1;
		var pageSize = 1000;
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/member-service/member/mine/member?token=" + $.cookie('tokenRh'),
			async: false,
			success: function(data) {
				console.log(data);
				memberId = data.id;
			}
		});
//		$.ajax({
//			type: "get",
//			url: "http://47.104.13.109/cart-service/goldcartselectAll?pageNum=1&pageSize=1000&userId=" + memberId,
//			async: true,
//
//			success: function(data) {
//				console.log(data);
//				var a = '';
//				for(var i = 0; i < data.list.length; i++) {
//					//					var pic = data.list[i].goodsPic;
//					var pic = '../../../images/coalltion/mianbao.jpg';
//					//判断天数
//					var time = 0;
//					if(data.list[i].reselltime) {
//						s1 = new Date(data.list[i].reselltime.replace(/-/g, "/"));
//						s2 = new Date();
//						var days = s2.getTime() - s1.getTime();
//						time = parseInt(days / (1000 * 60 * 60 * 24));
//
//					}
//					if(data.list[i].goodsGettime == null) {
//						a += '<li style="height: 2.77777rem;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right"><p>商品名：' + data.list[i].goodsName + '</p><p>金币:' + data.list[i].goodsgold + '</p><p class="active_red" style="position: absolute;bottom: 10px;">领取时间' + data.list[i].goodsExchangetime + '</p></div><div class="duihuan"><img src="../../../images/store/yifahuo.png"/></div></li>'
//					} else {
//						if(time >= 15) {
//							a += '<li style="overflow: hidden;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right" ><p></p>商品名：' + data.list[i].goodsName + '<p>金币:' + data.list[i].goodsgold + '</p><p class="active_red"  style="position: absolute;bottom: 1.625rem;">寄售时间' + data.list[i].reselltime + '</p></div><div class="duihuan"><img src="../../../images/store/duihuan.png"/></div></li>'
//						} else {
//							a += '<li style="overflow: hidden;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right" ><p></p>商品名：' + data.list[i].goodsName + '<p>金币:' + data.list[i].goodsgold + '</p><p class="active_red"  style="position: absolute;bottom: 1.625rem;">寄售时间' + data.list[i].reselltime + '</p></div><div class="duihuan"><img src="../../../images/store/duihuan.png"/></div><p style="clear: both;margin-top: 10px;text-align: center;"><button class="f28_s fangou"  style="padding: 10px 15px;border-radius: 20px;border: 1px solid red;background-color: white;color: red; margin: 0.3rem auto; z-index:1000;" data-a="' + data.list[i].cartId + '"data-b="' + data.list[i].userId + '"data-c="' + data.list[i].goodsName + '"data-d="' + data.list[i].goodsgold + '" data-e="' + data.list[i].orderSn + '"data-f="' + data.list[i].userName + '">申请平台返购</button></p></li>'
//						}
//
//					}
//				}
//				$('#gift_main').html(a);
//			},
//			error: function(error) {
//				alert("查询全部商品时出现错误")
//			}
//		});
		function zhuanmai(data, userId, goodsName, goodsgold, orderSn,userName,time) { //平台反购
//			console.log(data)
			console.log(userId)
//			console.log(goodsName)
//			console.log(goodsgold)
//			console.log(orderSn)
				if(time < 15){
					alert("还未到回购期，坚持售卖可获得更大收益");
					return;
				}
			$.ajax({
				type: "post",
				url: "http://47.104.13.109/cart-service/returnupdate",
				async: true,
				data: {
					cartId: data,
					userId: userId,
					userName : userName,
					goodsName: goodsName,
					proportion: proportion,
					goodsgold: goodsgold
				},
				success: function(res) {
					console.log(data);
					$.ajax({
						type: "get",
						url: "http://47.104.13.109/order-service/selectbyid?orderSn=" + orderSn,
						async: true,
						success: function(data2) {
							console.log(data2)
							$.ajax({
								type: "post",
								url: "http://47.104.13.109/order-service/updatereturn",
								data: {
									orderId: data2.orderId,
									proportion: proportion,
									goosGold : goodsgold
								},
								async: true,
								success: function(data3) {
									alert("返购成功");
									location.reload();
								},
								error: function(error) {
									alert("生成反购订单时发生错误，请联系管理员")
								}

							});
						},
						error: function(error) {
							alert("查询订单id时发生错误，请联系管理员")
						}
					});
					console.log(res);
					//					alert("已申请返购");
					//					window.location.reload();
				},
				error: function(error) {
					alert("申请反购时发生错误，请联系管理员")
				}
			});
		}

		function all_product() {
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/cart-service/goldcartselectAll?pageNum=1&pageSize=1000&userId=" + memberId,
				async: true,

				success: function(data) {
					console.log(data);
					var a = '';
					for(var i = 0; i < data.list.length; i++) {
						//					var pic = data.list[i].goodsPic;
						var pic = '../../../images/coalltion/mianbao.jpg';
						var time = 0;
					if(data.list[i].reselltime) {
						s1 = new Date(data.list[i].reselltime.replace(/-/g, "/"));
						s2 = new Date();
						var days = s2.getTime() - s1.getTime();
						time = parseInt(days / (1000 * 60 * 60 * 24));
						console.log(time);

					}
						if(data.list[i].isDelete == "1") {
							a += '<li style="overflow: hidden; padding-bottom: 0.3rem; height:auto;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right" style=" height:auto; width:65%;" ><p>商品名：' + data.list[i].goodsName + '</p><p>数量:' + data.list[i].goodsCount  + '</p><p>金币:' + data.list[i].goodsgold + '</p><p class="active_red" >领取时间：' + data.list[i].reselltime + '</p></div><div class="duihuan"><img src="../../../images/store/wanchengjimai.png"/></div></li>'
						} else {
							a += '<li style="overflow: hidden; padding-bottom: 0.3rem; height:auto;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right" style=" height:auto; width:65%;" ><p>商品名：' + data.list[i].goodsName + '</p><p>数量:' + data.list[i].goodsCount  + '</p><p>金币:' + data.list[i].goodsgold + '</p><p class="active_red" >寄售时间：' + data.list[i].reselltime + '</p> <p style="clear: both;margin-top: 10px;text-align: center;"><button class="f28_s fangou"  style="padding: 10px 15px;border-radius: 20px;border: 1px solid red;background-color: white;color: red;margin-left: -18%; z-index:1000;" data-a="' + data.list[i].cartId + '"data-b="' + data.list[i].userId + '"data-c="' + data.list[i].goodsName + '"data-d="' + data.list[i].goodsgold + '" data-e="' + data.list[i].orderSn + '"data-f="' + data.list[i].userName + '"data-g="' + time + '">申请平台返购</button></p> </div><div class="duihuan"><img src="../../../images/store/jimaizhong.png"/></div></li>'
						}
						$('#gift_main').html(a);
					}

				}
			});
			$('#type111').addClass('active_red red_border');
			$('#type222').removeClass('active_red red_border');
			$('#type333').removeClass('active_red red_border');
			$('#type444').removeClass('active_red red_border');
		}

		function wei() {
			$.ajax({
				type: "get",
				url: "http://47.104.13.109:80/cart-service/selectresell?pageNum=1&pageSize=1000&userId=" + memberId,
				async: true,
				success: function(data) {
					console.log(data);
					var a = '';
					$('#gift_main').html('');

					for(var i = 0; i < data.list.length; i++) {
						var time = 0;
					if(data.list[i].reselltime) {
						s1 = new Date(data.list[i].reselltime.replace(/-/g, "/"));
						s2 = new Date();
						var days = s2.getTime() - s1.getTime();
						time = parseInt(days / (1000 * 60 * 60 * 24));

					}
						a += '<li style="overflow: hidden; padding-bottom: 0.3rem; height:auto;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right" style=" height:auto; width:65%;" ><p>商品名：' + data.list[i].goodsName + '</p><p>数量:' + data.list[i].goodsCount  + '</p><p>金币:' + data.list[i].goodsgold + '</p><p class="active_red" >寄售时间：' + data.list[i].reselltime + '</p> <p style="clear: both;margin-top: 10px;text-align: center;"><button class="f28_s fangou"  style="padding: 10px 15px;border-radius: 20px;border: 1px solid red;background-color: white;color: red;margin-left: -18%; z-index:1000;" data-a="' + data.list[i].cartId + '"data-b="' + data.list[i].userId + '"data-c="' + data.list[i].goodsName + '"data-d="' + data.list[i].goodsgold + '" data-e="' + data.list[i].orderSn + '"data-f="' + data.list[i].userName + '"data-g="' + time + '">申请平台返购</button></p> </div><div class="duihuan"><img src="../../../images/store/jimaizhong.png"/></div></li>'
						$('#gift_main').html(a);
					}
				}
			});
			$('#type222').addClass('active_red red_border');
			$('#type111').removeClass('active_red red_border');
			$('#type333').removeClass('active_red red_border');
			$('#type444').removeClass('active_red red_border');

		}
		//申请反购
		$(document).on('click','.fangou',function(){
			zhuanmai( $(this).attr('data-a'), $(this).attr('data-b'), $(this).attr('data-c'), $(this).attr('data-d'), $(this).attr('data-e'), $(this).attr('data-f'), $(this).attr('data-g'))
		})

		function yi() {
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/cart-service/selectover?pageNum=1&pageSize=1000&userId=" + memberId,
				async: true,
				success: function(data) {
					console.log(data);
					var a = '';
					for(var i = 0; i < data.list.length; i++) {
						//					if(data.list[i].goodsResell==1){
						a += '<li style="overflow: hidden; padding-bottom: 0.3rem; height:auto;"><div class="gift_left"><img src="' + data.list[i].goodsPic + '"/></div><div class="gift_right" style=" height:auto; width:65%;" ><p>商品名：' + data.list[i].goodsName + '</p><p>数量:' + data.list[i].goodsCount  + '</p><p>金币:' + data.list[i].goodsgold + '</p><p class="active_red" >领取时间：' + data.list[i].reselltime + '</p></div><div class="duihuan"><img src="../../../images/store/wanchengjimai.png"/></div></li>'
						
						
					}
					$('#gift_main').html(a);
				}
			});
			$('#type333').addClass('active_red red_border');
			$('#type222').removeClass('active_red red_border');
			$('#type111').removeClass('active_red red_border');
			$('#type444').removeClass('active_red red_border');

		}

		function yiShop() {
			$.ajax({
				type: "get",
				url: "http://47.104.13.109:80/cart-service/goldcart",
				async: true,
				data: {
					userid: $.cookie("memberId")
				},
				success: function(res) {
					console.log(res)
					var list = res;
					var a = ''
					for(var i = 0; i < res.length; i++) {
						//待发货
						if(list[i].cartStatus == 0) {
							a += '<li style="overflow: hidden; padding-bottom: 0.3rem; height:auto;"><div class="gift_left"><img src="' + list[i].goodsPic + '"/></div><div class="gift_right" style=" height:auto; width:65%;" ><p>商品名：' + list[i].goodsName + '</p><p>数量:' + list[i].goodsCount  + '</p><p>金币:' + list[i].goodsGold + '</p><p class="active_red" >兑换时间：' + list[i].goodsExchangetime + '</p></div><div class="duihuan"><img src="../../../images/store/daifukuan.png"/></div><p style="clear: both;margin-top: 1rem;text-align: center;"></p></li>'
						}
						//已发货
						if(list[i].cartStatus == 1) {
							
							a += '<li style="overflow: hidden; padding-bottom: 0.3rem; height:auto;"><div class="gift_left"><img src="' + list[i].goodsPic + '"/></div><div class="gift_right" style=" height:auto; width:65%;" ><p>商品名：' + list[i].goodsName + '</p><p>数量:' + list[i].goodsCount  + '</p><p>金币:' + list[i].goodsGold + '</p><p class="active_red" >领取时间：' + list[i].goodsGettime + '</p> <div><span style="width: 30%;display: inline-table;">物流信息：</span><span style=" width:70%; display: inline-table; color:#ccc; border:1px solid #ccc;">' + list[i].goodsIntro + '</span></div> </div><div class="duihuan"><img src="../../../images/store/yifahuo.png"/></div><p style="clear: both;margin-top: 1rem;text-align: center;"></p></li>'
						}
					}
					$('#gift_main').html(a);
				}
			});
			$('#type333').removeClass('active_red red_border');
			$('#type222').removeClass('active_red red_border');
			$('#type111').removeClass('active_red red_border');
			$('#type444').addClass('active_red red_border');
		}
	</script>

</html>